//
//  AppDelegate.m
//  Running
//
//  Created by 郑东喜 on 2016/10/30.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

#import "AppDelegate.h"
#import "WXApi.h"
#import "WXApiManager.h"
#import "WKWebViewController.h"
#import "CheckNetWork.h"

#import "LoginVC.h"
#import "RigisterVC.h"

@interface AppDelegate ()<WXApiDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [CheckNetWork checkNetStatus];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netStatus:) name:@"netStatus" object:nil];
    
    [self setUpNav];
    
    [self setupWx];
    
    return YES;
}

#pragma mark - 通知模式
-(void)netStatus:(NSNotification*)notification {
    
    [CommonTool alertWithTitle:@"提示" withMsg:@"网络异常,请检查"];
    
    NSLog(@"%s  %d  ",__func__,__LINE__);
    return;
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
    
    [[NSNotificationCenter defaultCenter] removeObserver:@"netStatus"];
}

- (void)setUpNav {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    LoginVC *lvc = [[LoginVC alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:lvc];
    nav.navigationBarHidden = YES;
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    [self.window setBackgroundColor:[UIColor whiteColor]];
}

- (void)setupWx {
    [WXApi registerApp:weixinKey];//此为申请下来的key一般以wx开头
}

//程序之间的跳转
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return  [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}



@end
